package aidl.service;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AidlTest2 extends Activity {

	private Button button = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main1);

		Intent intent = new Intent(AidlTest2.this, MyService.class);
		bindService(intent, serviceConnection, BIND_AUTO_CREATE);

		button = (Button) findViewById(R.id.mybutton11);
		button.setOnClickListener(myListener);
	}

	private OnClickListener myListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			try {
				iServiceBinder.showSomethings(1);
			} catch (RemoteException e) {
				e.printStackTrace();
			}
		}
	};

	private IServiceBinder iServiceBinder = null;

	private ServiceConnection serviceConnection = new ServiceConnection() {

		@Override
		public void onServiceDisconnected(ComponentName name) {
			iServiceBinder = null;
		}

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			iServiceBinder = IServiceBinder.Stub.asInterface(service);
		}
	};

}
